<%@ page language="java" contentType="text/html; charset=utf8"%>
<!DOCTYPE>
<html>
<head>
	<title>riddle</title>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/base.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/font-awesome.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/login.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/statics/css/form.css">
	<script src="${pageContext.request.contextPath}/statics/js/jquery-3.2.1.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/layui/layui.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/layui/layui.all.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/form.js"></script>
	<script>
		$(function(){
			$("#id").val('${article.id}');
			$("#name").val('${article.name}');
			var publiz = eval('${article.publiz}');
			if(publiz){
				$("input[name='publiz']:first").attr("checked", "checked");
			} else {
				$("input[name='publiz']:last").attr("checked", "checked");
			}
			var first = eval('${article.first}');
			if(first){
				$("input[name='first']:first").attr("checked", "checked");
			} else {
				$("input[name='first']:last").attr("checked", "checked");
			}
			$.ajax({
				url:'${pageContext.request.contextPath}/admin/article/category',
				success:function(data){
					$("#category").html("");
					for(var i in data){
						var content = '<option value="' + data[i].id + '">' + data[i].name + '</option>';
						$("#category").append(content);
					}
					$("#category").val('${article.category.id}');
				}
			})
			$("#btnOk").click(function(){
				var content = UE.getEditor('editor').getContent();
				$.ajax({
					url:'${pageContext.request.contextPath}/admin/article/modifymodel',
					type:"post",
					data:getArticleData(),
					success:function(data){
						close();
					}
				})
			})
		});
		
		function getArticleData(){
			var res = {};
			res.id = $("#id").val();
			res.name = $("#name").val();
			res.content = UE.getEditor('editor').getContent();
			res.summary = UE.getEditor('editor').getContentTxt().substr(0, 500);
			var radio = $("input[name='first']:checked");
			if(radio.length > 0){
				res.first = $("input[name='first']:checked").val();
			} else {
				res.first = false;
			}
			radio = $("input[name='publiz']:checked");
			if(radio.length > 0){
				res.publiz = $("input[name='publiz']:checked").val();
			} else {
				res.publiz = false;
			}
			res["category.id"] = $("#category").val();
			return res;
		}
	</script>
	<script src="${pageContext.request.contextPath}/statics/js/jquery-3.2.1.js"></script>
	<script type="text/javascript" charset="gbk" src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="gbk" src="${pageContext.request.contextPath}/ueditor/ueditor.all.min.js"> </script>
	<script type="text/javascript" charset="gbk" src="${pageContext.request.contextPath}/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
	<input type="hidden" id="id"/>
	<div class="lv-form-container">
		<div class="lv-control-row">
			<div class="lv-label">标题</div>
			<input type="text" id="name" class="lv-control"/>
		</div>
	</div>
	<div>
		<script id="editor" type="text/plain" style="width:95%;height:450px;margin:0 auto;"></script>
	</div>
	<div class="lv-control-row">
		<div class="lv-label">是否公开</div>
		<input type="radio" name="publiz" class="lv-control" style="width:25px;" value="true"/><span>公开</span>
		<input type="radio" name="publiz" class="lv-control" style="width:25px;"  value="false"/><span>私密</span>
	</div>
	<div class="lv-control-row">
		<div class="lv-label">是否优先</div>
		<input type="radio" name="first" class="lv-control" style="width:25px;" value="true"/><span>是</span>
		<input type="radio" name="first" class="lv-control" style="width:25px;"  value="false"/><span>否</span>
	</div>
	<div class="lv-control-row">
			<div class="lv-label">文章类别</div>
			<select class="lv-control" id="category">
			</select>
		</div>
	<div class="lv-form-container" style="margin-bottom:10px;" id="btns">
		<div class="lv-control-row">
			<div class="lv-btn" id="btnCancel">取消</div>
			<div class="lv-btn" id="btnOk">发布</div>
		</div>
	</div>
<script type="text/javascript">
    var ue = UE.getEditor('editor');
    ue.ready(function() {
		UE.getEditor('editor').setContent('${article.content}');
	});
    
</script>
</body>
</html>